package com.icezzz.db_valid;

import cn.hutool.core.util.StrUtil;

public class ValidUtils {
    public static String valid(String tableName, String name, String type, String comment, int length) {
        name = name.toLowerCase();
        if (name.contains("type") && !"INT".equals(type)) {
            return "[" + tableName + "." + name + "]" + "应该为int类型";
        }
        if (name.contains("status") && !"INT".equals(type)) {
            return "[" + tableName + "." + name + "]" + "应该为int类型";
        }
        if ((name.endsWith("date") || name.endsWith("time")) && !"DATETIME".equals(type)) {
            return "[" + tableName + "." + name + "]" + "应该为datetime类型";
        }
        if ("url".equals(name) && length < 32) {
            return "[" + tableName + "." + name + "]" + "字段长度过小,长度为：" + length;
        }
        if ("password".equals(name) && length < 16) {
            return "[" + tableName + "." + name + "]" + "字段长度过小,长度为：" + length;
        }
        if ("VARBINARY".equals(type)) {
            return "[" + tableName + "." + name + "]" + "字段类型错误，不能为[VARBINARY]类型";
        }
        if (StrUtil.isBlank(comment)) {
            return "[" + tableName + "." + name + "]" + "字段注释为空";
        }
        if (StringUtils.containBlankOrUndefined(name)) {
            return "[" + tableName + "." + name + "]" + "字段含有特殊字符";
        }
        if (name.contains("name") && !"VARCHAR".equals(type)) {
            return "[" + tableName + "." + name + "]" + "应该为varchar类型";
        }
        if (name.contains("code") && !"VARCHAR".equals(type)) {
            return "[" + tableName + "." + name + "]" + "应该为varchar类型";
        }
        if ("description".equals(name) && !"TEXT".equals(type) && length < 500) {
            return "[" + tableName + "." + name + "]" + "字段长度过小,长度为：" + length;
        }
        return null;
    }
}
